// 当网页加载完成自动发送请求
// data/header.php  <div id="allHeader"></div>
// data/footer.php  <div id="allFooter"></div>
$(function(){
	$("#allHeader").load("data/header.php");
	$("#allFooter").load("data/footer.php");
});
// 轮播部分
$(function(){
	var focusBanner=function(){
		var $focusBanner=$(".j_bannerFocus"),
			$bannerList=$(".focusItem"),
			//$focusHandle=$(".focus-handle"),
			$bannerImg=$(".j_focusImg"),
			$nextBtn=$(".focusNext"),
			$prevBtn=$(".focusPrev"),
			$focusBubble=$(".slick_dots"),
			bannerLength=$bannerList.length,
			_index=0,
			_timer="";

			var _height=$(".j_focusImg").height();
			$focusBanner.height(_height);
			$bannerImg.height(_height);

			$(window).resize(function(){
				window.location.reload()
			});

			for(var i=0; i<bannerLength; i++){
				$bannerList.eq(i).css("zIndex",bannerLength-i);
				$focusBubble.append("<li><button></button></li>");
			}
			//console.log();
			$focusBubble.find("li").eq(0).addClass("focus_active");
			var bubbleLength=$focusBubble.find("li").length;

			$focusBubble.on("click","li",function(){
				$(this).addClass("focus_active").siblings().removeClass("focus_active");
				_index=$(this).index();
				changeImg(_index);
			});//点击轮换

			$bannerList.mouseenter(function(){
				clearInterval(_timer);
			}).mouseleave(function(){
				_timer=setInterval(function(){$nextBtn.click()},3500);
			});

			$nextBtn.on("click",function(){
				_index++;
				if(_index>bannerLength-1){
					_index=0;
				}
				//console.log(_index);
				changeImg(_index);
			});//下一张

			$prevBtn.on("click",function(){
				_index--;
				if(_index<0){
					_index=bannerLength-1;
				}
				changeImg(_index);
			});//上一张

			function changeImg(_index){
				//console.log(1);
				$bannerList.eq(_index).fadeIn(250);
				$bannerList.eq(_index).siblings().fadeOut(200);
				$focusBubble.find("li").removeClass("focus_active");
				$focusBubble.find("li").eq(_index).addClass("focus_active");
				clearInterval(_timer);
				_timer=setInterval(function(){$nextBtn.click()},3500);
			}//切换主函数
			_timer=setInterval(function(){$nextBtn.click()},3500);
			//$nextBtn.click();
	}();
});
// 新品首发部分
+function(){
	$(".j_newProduct").mouseenter(function(){
		$(this).find(".newProImg").toggleClass("f_hide");
	}).mouseleave(function(){
		$(this).find(".newProImg").toggleClass("f_hide");
	})
}();
// 人气推荐
+function(){
	var links = document.getElementsByClassName("popLink");
	var box = document.getElementsByClassName("pop_imgbox");
	for(var i=0;i<links.length;i++){
		links[i].onclick = function(e){
			e.preventDefault();
			var n = $(this).index();
			$(this).siblings().removeClass("popLink_hover");
			this.classList.add("popLink_hover");
			for(var i=0;i<box.length;i++){
				box[i].classList.add("f_hide");
			}
			box[n].classList.remove("f_hide");
		}
	}
}();
// 限时购进度条
+function(){
	// var selNum = $(".numTips").html();
	// console.log(selNum);
	var selTxt = document.getElementsByClassName("numTips");
	var w = document.getElementsByClassName("hasSellVolume");
	for(var i = 0;i<selTxt.length;i++){
		var selStart = selTxt[i].innerHTML.indexOf("剩");
		var selEnd = selTxt[i].innerHTML.indexOf("件");
		var selNum = selTxt[i].innerHTML.substring(selStart+1,selEnd);
		var numWidth = parseFloat(selNum/300)*150 + "px";
		w[i].style.width = numWidth;
		// console.log(selNum);
		// console.log(numWidth);
	}
}();
// 定时器
+function(){
	function clock(){
		var now = new Date();//.getTime();
		//console.log(now);
		var end = new Date(2017,4,22,22);//new Date(now+24*60*60*1000).getTime();
		//console.log(end);
		//console.log(end-now);
		var t = Math.floor((end-now)/1000);
		var d = Math.floor(t/3600/24);
		var h = Math.floor(t%(3600*24)/3600);
		var m = Math.floor(t%3600/60);
		var s = t%60;
		// console.log(t);
		// console.log(h);
		document.getElementsByClassName("jHour")[0].innerHTML = h;
		document.getElementsByClassName("jMinute")[0].innerHTML = m;
		document.getElementsByClassName("jSecond")[0].innerHTML = s;
		//console.log(now,end);
	}
	setInterval(clock,1000);
}();